home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / aboutd / aboutdlg.pas < prev    next >
Pascal/Delphi Source File  |  1995-12-22  |  3KB  |  121 lines

  1. unit Aboutdlg;
  2.  
  3. { Freeware by Jeff Atwood
  4.  
  5.   This unit provides a standard About.. box
  6.   for your application. It is modified from the
  7.   example in the Delphi Component Writer's Guide.
  8.  
  9.   This is my first Delphi project of any scale,
  10.   so if you can improve this code in any way,
  11.   send me a copy!
  12.  
  13.   To use, select Options/Install Components...
  14.   and select this file (ABOUTDLG.PAS)
  15.  
  16.   Thanks, Jeff
  17.   JAtwood159@AOL.COM
  18. }
  19.  
  20. interface
  21.  
  22. uses
  23.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  24.   Forms, Dialogs, About;
  25.  
  26. type
  27.   TAboutBoxDlg = class(TComponent)
  28.  
  29.   private
  30.     FProductName, FVersion, FCopyright, FComments: string;
  31.     fileHandle: THandle;
  32.     fileBuffer: Array [0..29] of Char;
  33.     wVersion: Word;
  34.     dVersion: Word;
  35.     winFlags: LongInt;
  36.  
  37.   public
  38.     function Execute: Boolean;
  39.  
  40.   published
  41.     property ProductName: string read FProductName write FProductName;
  42.     property Version: string read FVersion write FVersion;
  43.     property Copyright: string read FCopyright write FCopyright;
  44.     property Comments: string read FComments write FComments;
  45.   end;
  46.  
  47. var
  48.   AboutBox: TAboutBox;
  49.  
  50. procedure Register;
  51.  
  52. implementation
  53.  
  54. procedure Register;
  55. begin
  56.   RegisterComponents('Dialogs', [TAboutBoxDlg]);
  57. end;
  58.  
  59. function TAboutBoxDlg.Execute: Boolean;
  60. begin
  61.  
  62.      { Create dialog in memory }
  63.      AboutBox := TAboutBox.Create(Application);
  64.  
  65.      { Set dialog strings }
  66.      AboutBox.ProductName.Caption := ProductName;
  67.      AboutBox.Version.Caption := Version;
  68.      AboutBox.Copyright.Caption := Copyright;
  69.      AboutBox.Comments.Caption := Comments;
  70.      AboutBox.Caption := 'About ' + ProductName;
  71.  
  72.      { Get Win/Dos version numbers }
  73.      wVersion := LoWord(GetVersion);
  74.      dVersion := HiWord(GetVersion);
  75.      AboutBox.WinVersion.Caption := IntToStr(LO(wVersion)) + '.' +
  76.                                     IntToStr(HI(wVersion));
  77.      AboutBox.DosVersion.Caption := IntToStr(HI(dVersion)) + '.' +
  78.                                     IntToStr(LO(dVersion));
  79.  
  80.      winFlags := GetWinFlags;
  81.  
  82.      { Get math coprocessor status }
  83.      If winFlags And WF_80x87 > 0 Then
  84.         AboutBox.Coprocessor.Caption := 'Present'
  85.      Else
  86.         AboutBox.Coprocessor.Caption := 'Not Present';
  87.  
  88.      { Get CPU type }
  89.      If winFlags And WF_CPU486 > 0 Then
  90.         AboutBox.CPU.Caption := '486';
  91.      If winFlags And WF_CPU386 > 0 Then
  92.         AboutBox.CPU.Caption := '386';
  93.      If winFlags And WF_CPU286 > 0 Then
  94.         AboutBox.CPU.Caption := '286';
  95.  
  96.      { Get free memory, resources, disk space }
  97.      AboutBox.FreeMemory.Caption := IntToStr(GetFreeSpace(0) div 1000) + ' KB';
  98.      AboutBox.FreeResources.Caption := IntToStr(GetFreeSystemResources(GFSR_SYSTEMRESOURCES))
  99.                                        + '%';
  100.      AboutBox.FreeDisk.Caption := IntToStr(DiskFree(3) div 1000000) + ' MB';
  101.  
  102.      { Get user name and company name }
  103.      fileHandle := LoadLibrary('USER');
  104.  
  105.      if fileHandle >= HINSTANCE_ERROR then begin
  106.        If LoadString(fileHandle, 514, @fileBuffer, 30) <> 0 Then
  107.           AboutBox.userName.Caption := fileBuffer;
  108.        If LoadString(fileHandle, 515, @fileBuffer, 30) <> 0 Then
  109.           AboutBox.companyName.Caption := fileBuffer;
  110.        FreeLibrary(fileHandle);
  111.      end;
  112.  
  113.      with AboutBox do
  114.      begin
  115.        ProgramIcon.Picture.Graphic := Application.Icon;
  116.        Result := (ShowModal = IDOK);
  117.      end;
  118. end;
  119.  
  120. end.
  121.